window.ROOT = "";
(function() {
	
	var bussinessId=$("#identify").val();
	var serverData = {};
	var serverTable;
	jQuery(document).ready(function() {
	serverTable = jQuery('#dataTable').DataTable({
			"serverSide" : true,
			"ordering" : false,
			"ajax" : {
				"dataType" : "json",
				"type" : "get",
				"cache" : false,
				"url" : window.rootPath
						+ '/ui/bussinessAccusation/page?device=mobile&identify='+bussinessId,
				"data" : function(d) {
					return $.extend({}, d,
							serverData);
				}
			},
			columns : [
						{
							data : null,
							defaultContent : ""
						},
						{
							data : 'businesssellerBaseInfo.shopName'
						},
						{
							data : 'businesssellerBaseInfo.shopAdress'
						},
					
						{
							data : 'businesssellerBaseInfo.managementRange'
						},
						
						{
							data : 'businesssellerBaseInfo.managementPerson.name'
						},
						{
							data : 'accusationReson'
						},

						{
							data : 'accusationDate',
							render: function (data, type, full, meta) {
		                        if (data)
		                            return moment(data).format('YYYY/MM/DD HH:mm');
		                        else
		                            return '';
		                    }
						},
						{
							data : null,
							defaultContent : "",
							render : function(data,type, full,meta) {
								var operate="";
								
									operate= '<button type="button" class="btn btn-sm btn-info editBtn" title="编辑"><i class="fa fa-pencil"></i></button>'
										+ '<button type="button" class="btn btn-sm btn-info delBtn" title="删除"><i class="fa fa-remove"></i></button>';
								
								return operate;

							}
						} ],
			"drawCallback" : function(oSettings) {
				var k = 0;
				var total = oSettings.aiDisplay.length
						+ oSettings._iDisplayStart;

				for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
					$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
					k++;
				}

				serverTable.off('click', 'tr');
				serverTable.on('click','tr',function(event) {
					event = event|| window.event;
					var target = event.target|| event.scrElement;
					var data = serverTable.row(this).data();

					if (target.className.indexOf('fa-remove') != -1|| target.className.indexOf('delBtn') != -1) {

						deleteCheck(data);
					}

					if (target.className.indexOf('fa-pencil') != -1|| target.className.indexOf('editBtn') != -1) {

						editCheck(data);
					}

					return;
				});
			}
		});
	$(document).ready(function() {
		$("#goHome").attr("href",$("#goHome").attr("href")+"&&identify="+$('#identify').val());
	});
	//删除,使用的是restful风格的DELETE提交方式
	function deleteCheck(data){
		alert(data.id);
		if(confirm('确定删除该条记录?')){
			$.ajax({
				url:window.rootPath+'/ui/bussinessCheck/delete/'+data.id,
				dataType:'json',
				type:'post',
				data:'_method=DELETE',
				success:function(result){
					//返回成功
					if(result.code==1){
						//返回商家的举报页面
						window.location=window.rootPath+'/ui/bussinessCheck/index?device=mobile&identify='+data.businesssellerBaseInfo.id;
					}
				}
			});
		}
	};

	
	function editCheck(data){
		if(confirm('确定修改该条记录?')){
			//修改页面
			window.location=window.rootPath+"/ui/bussinessCheck/saveOrUpdate/"+data.id+"?device=mobile&identify="+data.businesssellerBaseInfo.id;
		}
	};
	

	$("#saveCheckBtn").click(function(){
		window.location=window.rootPath+"/ui/bussinessCheck/saveOrUpdate?device=mobile&identify="+bussinessId;
	});
	
});})();